package org.example.springbook.config;

import org.example.springbook.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class ErrorAdvice {

    @ExceptionHandler
    public Object hander(Exception e) {
        return Result.error(e.getMessage());
    }

    @ExceptionHandler
    public Object hander(NullPointerException e) {
        return Result.error("发生了NullPointerException",e.getMessage());
    }

    @ExceptionHandler
    public Object hander(ArithmeticException e) {
        return Result.error("ArithmeticException",e.getMessage());
    }
}
